import axios from 'axios'

const instance = axios.create({
    baseURL: 'http://127.0.0.1:8080',
    timeout: 60000,
    headers: {'Content-Type': 'application/json'} // JWT token
})

instance.interceptors.request.use(
    config => {
        // todo
        // JWT token
        const token = localStorage.getItem('token')
        if (token) {
            config.headers.Authorization = token
        }
        return config;
    },
    error => {
        // todo
        return Promise.reject(error)
    }
)

instance.interceptors.response.use(
    response => {
        // todo
        return response
    },
    error => {
        // todo
        return Promise.reject(error)
    }
)

export default instance